package com.heima.wemedia.scan.listener;

import com.heima.model.wemedia.dto.KafkaMessageConstants;
import com.heima.wemedia.scan.service.WmNewsAutoScanService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.context.annotation.Import;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class NewsAutoScanListener {

    @Resource
    private WmNewsAutoScanService wmNewsAutoScanListener;


    @KafkaListener(topics = KafkaMessageConstants.WM_NEWS_AUTO_SCAN_TOPIC,groupId = "group1")
    public void listenTopic1group1(ConsumerRecord<String, String> record) {

        String value = record.value();
        log.info("接收到消息 , 消息内容:{}", record.value());
        if (StringUtils.isNotBlank(value)) {
            log.info("开始进行文章自动审核 , 文章ID:{}", value);
            wmNewsAutoScanListener.autoScanNews(Long.valueOf(value));
            log.info("审核结束 , 文章ID:{}", value);
        }
    }
}
